package com.itheima.tcp02;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/*
服务端
 */
public class Server {

    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(8888);
        Socket accept = ss.accept();
        InputStream is = accept.getInputStream();
        //需要字节->字符的桥梁
        // 把字节输入流变成 了字符输入流
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String s;
        while ((s=reader.readLine())!=null){
            System.out.println(s);
        }
        //回馈消息
        String result="我收到了";
        OutputStream os = accept.getOutputStream();
        // 需要字符->字节的桥梁
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os));
        writer.write(result);
        writer.flush();
        //释放资源
        writer.close();
        reader.close();
        ss.close();
    }
}
